// room script file
// Tween Tutorial 1: Room Objects and the basics of Tween
// Room 1 has a room object called oBall (a red ball)

function room_AfterFadeIn()
{
  StartCutscene(eSkipESCOnly);
  player.Say("The Tween module allows you to programatically create animated effects with many of the AGS objects including Objects, Characters, and GUIs.");
  player.Say("Let's go over the basics.");
  
  // SecondsToLoops comes with the Tween module. it allows you to convert seconds to AGS game loops based on the current framerate.
  Wait(SecondsToLoops(1.0));  // Wait 1 second. 
  
  player.Say("Room Objects, for example, have three Tween types: Position, Transparency, and Image.");
  player.Say("Let's mess around with the position and transparency.");
  oBall.Visible = true;
  player.Say("We'll use this red ball.");
  
  player.Say("Let's tween its transparency by fading it out:");
  // Tween the ball's transparency from its current transparency to 100%.
  oBall.TweenTransparency(2.5, 100); // Note that transparency must be from 0 to 100%.
  player.Say("And fading it in to 50%.");
  oBall.TweenTransparency(2.5, 50);
  player.Say("And fading it in to 100%.");
  oBall.TweenTransparency(2.5, 0); // 0% transparency in AGS means 100% visible ;)
  
  player.Say("Now, let's tween the ball's position to move it around.");
  // Tween the ball's position in 1.5 seconds from its current position to x: 0 and y: 120
  oBall.TweenPosition(1.5, 0, 120);
  
  short ballX = oBall.X;
  short ballY = oBall.Y;
  
  player.Say("If you're familiar with AGS you're probably thinking: \"I could have used Object.Move() function!\"");
  player.Say("All tweens have a feature that AGS lacks, that we'll call timing.");
  player.Say("These are optional parameters that can tell whether the object should accelerate on start, decelerate at the end or both.");
  player.Say("We call these EaseIn, EaseOut, and EaseInEaseOut.");
  player.Say("By default, the timing is just Linear.");
  oBall.TweenPosition(2.0, 279, 120, eLinearTween);
  
  player.Say("EaseIn. Notice how it starts out slow.");
  oBall.TweenPosition(2.0, 0, 120, eEaseInTween);
  
  player.Say("EaseOut. Notice how it slows down at the end.");
  oBall.TweenPosition(2.0, 279, 120, eEaseOutTween);
  
  player.Say("EaseInEaseOut. Notice how it both accelerates and decelerates.");
  oBall.TweenPosition(2.0, 0, 120, eEaseInEaseOutTween);
  
  player.Say("And here's Object.Move() for comparison.");
  oBall.Move(279, 120, 4, eBlock, eAnywhere);
  
  player.Say("I hope you noted how smoother you can make your movements with these!");
  
  player.Say("Another thing you can do is that you can set the tween to Block and NoBlock.");
  player.Say("You can also set it to Repeat, or to reverse when repeating.");
  player.Say("Here's repeat:");
  // All non-blocking tweens return their duration in loops.
  Wait(oBall.TweenPosition(1.0, 0, 120, eLinearTween, eRepeatTween) * 3); // Wait 3 repeats
  oBall.StopAllTweens(); // This can stop all the tweens affecting an object.
  player.Say("And here's ReverseRepeat in action:");
 
  Wait(oBall.TweenPosition(1.0, 279, 120, eLinearTween, eReverseRepeatTween) * 4); // Wait 4 repeats
  oBall.StopAllTweens();
  
  player.Say("Note that the repeats are only non-blocking.");
  player.Say("It doesn't make sense to infintely repeat something and have the game wait forever, right?");
  
  Wait(SecondsToLoops(2.0));
  
  player.Say("You can also control when and how to stop the tweens.");
  player.Say("Let's go back to that earlier tween we were playing with:");
  float duration = 2.0;
  oBall.X = ballX;
  oBall.Y = ballY;
  oBall.Transparency = 0;
  oBall.TweenPosition(duration, 279, 120, eLinearTween);
  
  player.Say("We can stop a non-blocking tween at any time. Let's run the tween the same way but stop it half way.");
  oBall.X = ballX;
  oBall.Y = ballY;
  oBall.TweenPosition(duration, 279, 120, eLinearTween, eNoBlockTween); // remember, it has to be non-blocking!
  WaitSeconds(duration * 0.5); // handy-dandy function that comes with the Tween module!
  oBall.StopAllTweens(ePauseTween); // ePauseTween comes as the default
  WaitSeconds(duration * 0.5);
  player.Say("See, no problem!");
  
  player.Say("From version 1.2, we can make it reset back to its original position.");
  oBall.X = ballX;
  oBall.Y = ballY;
  oBall.TweenPosition(duration, 279, 120, eLinearTween, eNoBlockTween);
  WaitSeconds(duration * 0.5);
  oBall.StopAllTweens(eResetTween); // Go back to the beginning at this point!
  WaitSeconds(duration * 0.5);
  
  player.Say("We can also make it immediatelly snap to the its final destination.");
  oBall.X = ballX;
  oBall.Y = ballY;
  oBall.TweenPosition(duration, 279, 120, eLinearTween, eNoBlockTween);
  WaitSeconds(duration * 0.5);
  oBall.StopAllTweens(eFinishTween); // Jump to the end of the tween at this point!
  WaitSeconds(duration * 0.5);
  
  player.Say("Fun!");
  
  // Fade out the ball while moving it to x 0, y 120.
  oBall.TweenPosition(duration, oBall.X, oBall.Y + 50, eEaseOutTween, eNoBlockTween);
  oBall.TweenTransparency(duration, 100, eEaseOutTween);
  
  player.Say("Well, we're done in this room.");
  player.Say("Coming up next, information on Characters and GUIs.");
  
  EndCutscene();
  player.ChangeRoom(2);
}